#include <rclcpp/rclcpp.hpp>
#include <rclcpp/timer.hpp>
#include <std_msgs/msg/string.hpp>
#include <chrono>

using namespace std::chrono_literals;

class printStringNode:public rclcpp::Node{
public:
  printStringNode(std::string name):Node(name){
    pub_=this->create_publisher<std_msgs::msg::String>("print_string_pub",10);
    timer_=this->create_wall_timer(1s,std::bind(&printStringNode::timerCallback,this));
  }

  void timerCallback(){
    // create data
    auto str=std_msgs::msg::String();
    str.data="Hello world!";
    // publish
    pub_->publish(str);
  }

private:
  rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_{nullptr};
  rclcpp::TimerBase::SharedPtr timer_{nullptr};
};

int main(int argc,char** argv){
    rclcpp::init(argc,argv);
    auto node=std::make_shared<printStringNode>("print_string_node");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}